package com.lanou.musicproject.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.musicproject.R;
import com.lanou.musicproject.bean.MyMusicList;
import java.util.ArrayList;

/**
 * Created by dllo on 15/11/5.
 */
public class PopupAdapter extends BaseAdapter {
    private ArrayList<MyMusicList> lists;
    private MyMusicList enList;
    private Context mContext;
    public PopupAdapter (Context c,ArrayList<MyMusicList>l){
        mContext = c;
        lists = l ;
        Log.i("lidong","++++++++"+lists);
    }
    @Override
    public int getCount() {
        return lists != null && lists.size() > 0 ? lists.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return lists != null && lists.size() > 0 ? lists.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.popup_item,null);
            holder = new MyViewHolder();
            holder.popup_singer = (TextView) convertView.findViewById(R.id.popup_singer);
            holder.popup_songName = (TextView) convertView.findViewById(R.id.popup_songName);
            convertView.setTag(holder);
        }else {
            holder = (MyViewHolder) convertView.getTag();

        }
        enList = (MyMusicList) getItem(position);
        Log.i("===========","++++++++>>>>"+enList.getName());
        holder.popup_songName.setText(enList.getName());
        holder.popup_singer.setText(enList.getSinger());
        return convertView;
    }
    public class MyViewHolder{
        public TextView popup_songName,popup_singer;
    }
}
